package com.ylzinfo.ms.qycloud.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylzinfo.ms.qycloud.entity.SysUser;
import com.ylzinfo.ms.qycloud.mapper.UserMapper;
import com.ylzinfo.ms.qycloud.service.UserService;
import com.ylzinfo.ms.qycloud.utils.PageDto;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Product: IntelliJ IDEA
 * @Author Rogchen rogchen128@gmail.com
 * @Created Date: 2019/3/26 15:44
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public SysUser get(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysUser> findPageByMap(int offset, int limit) {
        PageHelper.startPage(offset, limit);
        PageInfo pageInfo = new PageInfo(userMapper.findPageByMap());
        System.out.println("统计：" + pageInfo.getTotal());
        return null;
    }

    @Override
//    不适合数据量大查询
    public PageDto<SysUser> findPage(int offset, int limit) {
        PageDto<SysUser> page = new PageDto(offset,limit);
        Example sysUser = new Example(SysUser.class);
        page.setList(userMapper.selectByExampleAndRowBounds(sysUser, new RowBounds(offset, limit)));
        page.setTotal(userMapper.selectCount(null));
        return page;
    }
}
